<!-- 引入评论无限极插件 treetable -->
<link rel="stylesheet" href="/assets/treetable/jquery.treetable.css">
<link rel="stylesheet" href="/assets/treetable/jquery.treetable.theme.default.css">

<style>
    .fly-rank dl {
        text-align: left;
    }
</style>
<div class="layui-container">
    <div class="layui-row layui-col-space15">

        <!-- 左侧 -->
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <h1>{$post.title}</h1>

                <!-- 状态信息 -->
                <div class="fly-detail-info">

                    <!-- 帖子状态 -->
                    {if condition="$post.state eq '1'"}
                    <span class="layui-badge layui-bg-black">置顶</span>
                    {elseif condition="$post.state eq '2'"}
                    <span class="layui-badge layui-bg-red">精帖</span>
                    {elseif condition="$post.state eq '3'"}
                    <span class="layui-badge layui-bg-orange">热门</span>
                    {/if}


                    <!-- 帖子采纳状态 -->
                    {if condition="$post.accept"}
                    <span class="layui-badge" style="background-color: #5FB878;">已采纳
                    </span>
                    {else /}
                    <span class="layui-badge" style="background-color: #999;">
                        未采纳
                    </span>
                    {/if}

                    <!-- 删除帖子 -->
                    {if condition="$Think.cookie.LoginUser"}
                    {if condition="$Think.cookie.LoginUser['id'] ==$post['userid']"}
                    <span id="del" class="layui-btn layui-btn-xs jie-admin" type="del">
                        删除
                    </span>
                    {/if}
                    {/if}

                    <!-- 收藏帖子 -->
                    {if condition="$Think.cookie.LoginUser"}
                    {if condition="$Collect"}
                    <span id="collect" class="layui-btn layui-btn-xs" type="collect">
                        已收藏
                    </span>
                    {else /}
                    <span id="collect" class="layui-btn layui-btn-xs" type="collect">
                        收藏
                    </span>
                    {/if}
                    {/if}

                    <!-- 评论和查看次数 -->
                    <span class="fly-list-nums">
                        <!-- 评论数量 -->
                        <a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i>
                            {$post.comment_total}
                        </a>


                        <i class="iconfont" title="人气">&#xe60b;</i>
                        {$post.visit_total}

                    </span>
                </div>


                <!-- 帖子的头部内容 -->
                <div class="detail-about">
                    <!-- 帖子头像 -->
                    <a class="fly-avatar" href="javascript:void(0)">
                        {if condition="$post.user.avatar && is_file('.'.$post.user.avatar)"}
                        <img src="{$post.user.avatar}" />
                        {else /}
                        <img src="/assets/home/images/avatar.jpg">
                        {/if}
                    </a>

                    <!-- 昵称认证状态和发帖时间 -->
                    <div class="fly-detail-user">
                        <a href="javascript:void(0)" class="fly-link">

                            <!-- 昵称 -->
                            <cite>{$post.user.nickname}</cite>

                            <!-- 认证状态 -->
                            {if condition="$post.user.auth"}
                            <i class="iconfont icon-renzheng" title="认证信息：{{ rows.user.approve }}"></i>
                            {/if}

                            <!-- VIP -->
                            {if condition="$post.user.vip gt 0"}
                            <i class="layui-badge fly-badge-vip">VIP{$post.user.vip}</i>
                            {/if}
                        </a>
                        <!-- 发帖时间 -->
                        <span>{$post.createtime}</span>
                    </div>

                    <!-- 悬赏积分编辑 -->
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
                        <!-- 悬赏积分 -->
                        <span style="padding-right: 10px; color: #FF7200">
                            悬赏：{$post.point}积分
                        </span>

                        <!-- 编辑此贴 -->
                        {if condition="$Think.cookie.LoginUser"}
                        {if condition="$Think.cookie.LoginUser['id'] ==$post['userid']"}
                        {if condition="!$post['accept']"}
                        <span class="layui-btn layui-btn-xs jie-admin" type="edit">
                            <a href="{:url('home/post/edit',['postid'=>$post['id']])}">
                                编辑此贴
                            </a>
                        </span>
                        {/if}
                        {/if}
                        {/if}

                    </div>
                </div>

                <!-- 帖子的正文内容 -->
                <div class="detail-body photos">
                    {$post.content}
                </div>
            </div>

            <!-- 评论 -->
            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend>
                </fieldset>



                <!-- 插件调用评论 -->
                <table id="commentlist" style="border: 0;">
                    {if condition="$commentlist"}
                    {foreach $commentlist as $item}
                    <tr data-tt-id="{$item.id}" data-tt-parent-id="{$item.pid}">
                        <td>
                            <li>
                                <div class="detail-about detail-about-reply">
                                    <!-- 头像 -->
                                    {if condition="$item.user.avatar && is_file('.'.$item.user.avatar)"}
                                    <a class="fly-avatar" href="">
                                        <img src="{$item.user.avatar}" alt=" ">
                                    </a>
                                    {else /}
                                    <a class="fly-avatar" href="">
                                        <img src="/assets/home/images/avatar.jpg" alt=" ">
                                    </a>
                                    {/if}


                                    <!-- 昵称状态 -->
                                    <div class="fly-detail-user">
                                        <a href="" class="fly-link">
                                            <!-- 昵称 -->
                                            <cite>{$item.user.nickname}</cite>

                                            <!-- 认证信息 -->
                                            {if condition="$item.user.auth gt 0"}
                                            <i class="iconfont icon-renzheng" title="认证信息：XXX"></i>
                                            {/if}

                                            {if condition="$item.user.vip"}
                                            <i class="layui-badge fly-badge-vip">VIP{$item.user.vip}</i>
                                            {/if}
                                        </a>

                                        {if condition="$item.level==0"}
                                        <span>(楼主)</span>
                                        {/if}

                                    </div>

                                    <!-- 评论时间 -->
                                    <div class="detail-hits">
                                        <span>{$item.createtime}</span>
                                    </div>

                                </div>

                                <!-- 评论内容 -->
                                <div class="detail-body jieda-body photos">
                                    <p>{$item.content}</p>
                                </div>


                                <!-- 功能 -->
                                <div class="jieda-reply">
                                    <!-- 点赞数 -->
                                    <span class="jieda-zan {$item.like_checked ? 'zanok' : ''}" type="zan">
                                        <i class="iconfont icon-zan"></i>
                                        <em>{$item.like_total}</em>
                                    </span>

                                    <!-- 回复按钮 -->
                                    <span type="reply">
                                        <i class="iconfont icon-svgmoban53"></i>
                                        回复
                                    </span>


                                    <!-- 删除按钮和采纳 -->
                                    <!-- 帖子发布人、评论本人 这两种情况是可以删除评论 -->
                                    <div class="jieda-admin">
                                        {if condition="$Think.cookie.LoginUser"}
                                        {if condition="$Think.cookie.LoginUser['id'] == $post['userid'] ||
                                        $Think.cookie.LoginUser['id'] == $item['userid']"}
                                        <span type="del">删除</span>
                                        {/if}
                                        {/if}


                                        <!-- 帖子发布人  帖子未采纳 -->
                                        {if condition="$Think.cookie.LoginUser"}
                                        {if condition="$Think.cookie.LoginUser['id'] == $post['userid'] &&
                                        $Think.cookie.LoginUser['id'] != $item['userid']"}
                                        {if condition="!$post['accept']"}
                                        <span class="jieda-accept" type="accept">采纳</span>
                                        {/if}
                                        {/if}
                                        {/if}
                                    </div>
                                </div>
                            </li>
                        </td>
                    </tr>
                    {/foreach}
                    {else /}
                    <li class="fly-none">消灭零回复</li>
                    {/if}


                </table>



                <!-- 回复评论 -->
                {if condition="!$post['accept']"}
                <div class="layui-form layui-form-pane">
                    <form method="post">
                        <div class="layui-form-item layui-form-text">
                            <a name="comment"></a>
                            <div class="layui-input-block">
                                <textarea id="L_content" name="content" required lay-verify="required"
                                    placeholder="请输入内容" class="layui-textarea fly-editor"
                                    style="height: 150px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="jid" value="123">
                            <button class="layui-btn" lay-filter="*" lay-submit>提交回复</button>
                        </div>
                    </form>
                </div>
                {/if}
            </div>
        </div>

        <!-- 右侧 -->
        <div class="layui-col-md4">

            <!-- 热门访问 -->
            <div class="fly-panel">
                <h3 class="fly-panel-title">本周热议</h3>
                {if condition="$week"}
                <ul class="fly-panel-main fly-list-static">
                    {foreach $week as $item}
                    <li>
                        <a href="{:url('home/index/info', ['postid' => $item['id']])}" target="_blank">
                            {$item.title}
                        </a>
                    </li>
                    {/foreach}
                </ul>
                {/if}
            </div>

            <!-- 本周热门回帖 -->
            <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
                <h3 class="fly-panel-title">回贴周榜</h3>
                {if condition="$userlist"}
                <dl>
                    {foreach $userlist as $item}
                    <dd>
                        <a href="javascript:void(0)">
                            {if condition="$item.avatar AND is_file('.'.$item.avatar)"}
                            <img src="{$item.avatar}">
                            {else /}
                            <img src="/assets/home/images/avatar.jpg">
                            {/if}
                            <cite>{$item.nickname}</cite>
                            <i>{$item.num}次回答</i>
                        </a>
                    </dd>
                    {/foreach}
                </dl>
                {/if}
            </div>


            <!-- 二维码 -->
            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img src="/assets/home/images/weixin.jpg" style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p>
            </div>
        </div>
    </div>
</div>
<script src="/assets/treetable/jquery.js"></script>
<script src="/assets/treetable/jquery.treetable.js"></script>

<script>

    $("#commentlist").treetable({ expandable: true });

    layui.use(['form', 'jquery'], function () {
        var $ = layui.jquery
        var postid = `{$post.id}`

        // 删除帖子点击事件
        $("#del").click(function () {
            console.log(123546);
            // 确认对话框
            layer.confirm('是否删除帖子', { icon: 3, title: '提示' }, function (index) {
                // 关闭弹框
                layer.close(index);

                // 发送ajax请求
                $.ajax({
                    url: `{:url('home/post/del')}`,
                    type: 'post',
                    data: { postid: postid },
                    dataType: 'json',
                    success: function (success) {
                        if (success.code == 1) {
                            // 删除 成功
                            layer.msg(success.msg, function () {
                                location.href = `{:url('home/index/index')}`;
                            })
                            return false;
                        } else {
                            // 删除失败
                            layer.msg(success.msg)
                        }
                    }
                })
            })
        })


        // 删除帖子点击事件
        $("#collect").click(function () {

            // 发送ajax请求
            $.ajax({
                url: `{:url('home/index/collect')}`,
                type: 'post',
                data: { postid: postid },
                dataType: 'json',
                success: function (success) {
                    if (success.code == 1) {
                        // 删除 成功
                        layer.msg(success.msg)
                    } else {
                        // 删除失败
                        layer.msg(success.msg)
                    }
                }
            })

        })

        // 点赞点击事件
        // $('.jieda-zan').click(function (e) {
        //     var $this = $(e.target);
        //     console.log($this);
        // });
    })
</script>